/**
 * Created by LeeXyan on 16-8-8.
 */

/**
 * 更换右边主题
 */
(function(){
    //自定义指令,用来关联选择框和vm
    Vue.directive('selectpicker',{
        params:['options'],
        twoWay: true,
        deep: true,
        bind:function(){
            var _this=this;
            $(_this.el).on("changed.bs.select",function(e){
                _this.set(e.target.value);
            });
        },
        paramWatchers:{
            options:function(val,oldVal){
            	this.el.innerHTML="";
                var i=val.length;
                while(i--){
                    var o=val[i];
                    var node=document.createElement("option")
                    node.value=o.id;
                    node.innerHTML=o.name;

                    this.el.appendChild(node);
                }

                $(this.el).selectpicker('refresh');
            }
        },
        update:function(newValue,oldValue){
            $(this.el).val(newValue);
            $(this.el).selectpicker('refresh').trigger("change");
        },
        unbind:function(){
            $(this.el).off().selectpicker('destroy');
        }
    });

})();
